package com.px.user.mapper;

import com.px.user.entity.InviteCode;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface InviteCodeMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into invite_code (fromUserId,roomId,code) values (#{fromUserId},#{roomId},#{code})")
    void insert(InviteCode inviteCode);

    @Update("update invite_code set code=ifnull(#{code},code) where id=#{id}")
    void updateById(InviteCode inviteCode);

    @Select("select * from invite_code where fromUserId=#{fromUserId}")
    List<InviteCode> getInviteCode(Long fromUserId);

    @Select("select * from invite_code where code=#{code}")
    InviteCode findByCode(String code);

    @Delete("delete from invite_code where id=#{id} and fromUserId=#{fromUserId}")
    void delete(Map claims);
}
